//
//  AppDelegate.m
//  Tour
//
//  Created by dllo on 15/10/21.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "AppDelegate.h"
#import "AdvanceEdit.h"
#import "UMSocial.h"
#import "ZGSLeadViewController.h"
#import <AFNetworking.h>
//#import "<#header#>"
//#import ""

//#import "<#header#>"
@interface AppDelegate ()<UITabBarControllerDelegate, UIScrollViewDelegate, UIAlertViewDelegate>
@property (nonatomic, assign)BOOL isOut;


@end

@implementation AppDelegate
//-(void)gotoMain{
//    //如果第一次进入没有文件，我们就创建这个文件
//    NSFileManager *manager=[NSFileManager defaultManager];
//    //判断 我是否创建了文件，如果没创建 就创建这个文件（这种情况就运行一次，也就是第一次启动程序的时候）
//    if (![manager fileExistsAtPath:[NSHomeDirectory() stringByAppendingString:@"aa.txt"]]) {
//        [manager createFileAtPath:[NSHomeDirectory() stringByAppendingString:@"aa.txt"] contents:nil attributes:nil];
//    }
//    
//}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    DeclineViewController *declineVC = [[DeclineViewController alloc] init];
    UINavigationController *declineNAVC = [[UINavigationController alloc] initWithRootViewController:declineVC];
    declineVC.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"首页" image:[UIImage imageNamed:@"cba.png"] tag:1001] autorelease];
    
    DestionViewController *destionVC = [[DestionViewController alloc] init];
    UINavigationController *destionNAVC = [[UINavigationController alloc] initWithRootViewController:destionVC];
    destionVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"目的地" image:[UIImage imageNamed:@"liebiao.png"] tag:1002];
    
    HotViewController *hotVC = [[HotViewController alloc] init];
    UINavigationController *hotNAVC = [[UINavigationController alloc] initWithRootViewController:hotVC];
    hotVC.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"推辞" image:[UIImage imageNamed:@"abc.png"] tag:1003] autorelease];
    
    MeViewController *meVC = [[MeViewController alloc] init];
    UINavigationController *meNAVC = [[UINavigationController alloc] initWithRootViewController:meVC];
    meVC.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"我的" image:[UIImage imageNamed:@"321.png"] tag:1004]autorelease];
    
    self.tab = [[UITabBarController alloc] init];
    self.tab.viewControllers = @[declineNAVC, destionNAVC, hotNAVC, meNAVC];
    self.tab.tabBar.translucent = NO;
    self.tab.tabBar.barTintColor = [UIColor whiteColor];
    self.tab.tabBar.tintColor = [UIColor blackColor];
    self.window.rootViewController = self.tab;
    self.tab.delegate = self;
    [UMSocialData setAppKey:@"5632bfafe0f55a7d78002859"];
    // (分享) 友好界面
    CGSize size = [UIScreen mainScreen].bounds.size;
    
    UIImageView *imageView = [[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, size.width, size.height)] autorelease];
    imageView.image = [UIImage imageNamed:@"youhao.jpg"];
    
    [self.tab.view addSubview:imageView];
    
    [UIView animateWithDuration:2 delay:2 options:UIViewAnimationOptionTransitionCurlDown animations:^{
        imageView.alpha = 0;
        
    } completion:^(BOOL finished) {
        
        [imageView removeFromSuperview];
    }];
    
    //     tabBar 是否透明
    self.tab.tabBar.translucent = NO;
    //获取沙盒中的版本号
    
    
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSString *key = (NSString *)kCFBundleVersionKey;
    NSString *sandBoxVersion = [defaults valueForKeyPath:key];
    // 获取当前版本号
    NSDictionary *md = [NSBundle mainBundle].infoDictionary;
    NSString *currentVersion = md[key];
    if ([currentVersion compare:sandBoxVersion] == NSOrderedDescending)
    {
        NSLog(@"ss ");
        // 存储当前版本号
        [defaults setObject:currentVersion forKey:key];
        //锁定当前线程
        [defaults synchronize];
        // 第一次使用当前版本  显示引导页
        [self showGuidePage];
    }
    else
    {
        NSLog(@"sssdsf");
        // 不是第一次使用当前版本  显示主页面
        [self.window setRootViewController:self.tab];
        
    }

//    [self iswlan];
    return YES;
}

- (void)showGuidePage
{
    ZGSLeadViewController *scroller = [[ZGSLeadViewController alloc] init];
    [self.window setRootViewController:scroller];
}

- (void)change
{
    if (self.window.alpha == 0.5) {
        self.window.alpha = 1;
    } else {
        self.window.alpha = 0.5;
    }
}

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    return UIInterfaceOrientationMaskPortrait;
}
- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
